package com.open.party.cloud.view.examine

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.parent.AppTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.view.examine.fragment.ExamineClassesAttendanceListForAllFragment
import com.open.party.cloud.view.examine.fragment.ExamineClassesAttendanceListForTodayFragment
import kotlinx.android.synthetic.main.title_tab_view_page.*

class ExamineAttendanceHistoryActivity : AppTitleBaseActivity() {

    open var classId: String? = null

    override fun getLayoutResId(): Int = R.layout.title_tab_view_page

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        classId = intent.getStringExtra("classId")
        setViewTitle("签到记录")

        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        val fragments: ArrayList<Fragment> = ArrayList()

//        titleList.add("今日考勤")
        titleList.add("所有考勤")

//        fragments.add(ExamineClassesAttendanceListForTodayFragment())
        fragments.add(ExamineClassesAttendanceListForAllFragment())

        initTab(titleList, fragments)
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);
        scrollTab.visibility = View.GONE
        scrollTab.setTitles(titles)
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }
    }
}